
package com.wyzz.hr.action;

import java.util.List;
import java.util.Map;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.base.ComonBeans;
import com.wyzz.hr.bo.IPerfcrittypeBO;
import com.wyzz.hr.bo.IPerfplanperiodBO;
import com.wyzz.hr.bo.IPerfschematypeBO;
import com.wyzz.hr.pojo.Perfcrittype;
import com.wyzz.hr.pojo.Perfplanperiod;
import com.wyzz.hr.pojo.Perfschematype;

public class PerfConfigAction extends BaseAction {

	public PerfConfigAction() {
		pctBo = (IPerfcrittypeBO) getBean("perfcrittypeBO");
		pstBo = (IPerfschematypeBO) getBean("perfschematypeBO");
		pppBo = (IPerfplanperiodBO) getBean("perfplanperiodBO");
	}

	public String execute() {
		return "success";
	}

	public String pctConfigInit() {
		crittypeList = pctBo.loadAll();
		return "success";
	}

	public Perfcrittype savePct(Perfcrittype pct) {
		if (pct.getPctSortId() == null)
			pct.setPctSortId(pctBo.getMaxSortId());
		pctBo.save(pct);
		return pct;
	}

	public String deletePct(String pctId) {
		int count = pctBo.getRelatePcCount(pctId);
		if (count > 0) {
			return "FAIL";
		} else {
			pctBo.delete(pctId);
			return "SUCC";
		}
	}

	public String savePctSort(String ids[]) {
		if (ids == null || ids.length == 0) {
			return "SUCC";
		} else {
			pctBo.savePctOrder(ids);
			return "SUCC";
		}
	}

	public String pstConfigInit() {
		schematypeList = pstBo.loadAll();
		return "success";
	}

	public Perfschematype savePst(Perfschematype pst) {
		if (pst.getPstSortId() == null)
			pst.setPstSortId(pstBo.getMaxSortId());
		pstBo.save(pst);
		return pst;
	}

	public String deletePst(String pstId) {
		int count = pstBo.getRelatePsCount(pstId);
		if (count > 0) {
			return "FAIL";
		} else {
			pstBo.delete(pstId);
			return "SUCC";
		}
	}

	public String savePstSort(String ids[]) {
		if (ids == null || ids.length == 0) {
			return "SUCC";
		} else {
			pstBo.savePstOrder(ids);
			return "SUCC";
		}
	}

	public String pppConfigInit() {
		pppList = pppBo.searchAllPpp();
		pppClassList = ComonBeans.getValuesToMap("pppClass",
				new boolean[] { true });
		return "success";
	}

	public Perfplanperiod savePpp(Perfplanperiod ppp) {
		pppBo.save(ppp);
		return ppp;
	}

	public String deletePpp(String pppId) {
		int count = pppBo.getRelatePpCount(pppId);
		if (count > 0) {
			return "FAIL";
		} else {
			pppBo.delete(pppId);
			return "SUCC";
		}
	}

	public List getCrittypeList() {
		return crittypeList;
	}

	public void setCrittypeList(List crittypeList) {
		this.crittypeList = crittypeList;
	}

	public List getSchematypeList() {
		return schematypeList;
	}

	public void setSchematypeList(List schematypeList) {
		this.schematypeList = schematypeList;
	}

	public Map getPppClassList() {
		return pppClassList;
	}

	public void setPppClassList(Map pppClassList) {
		this.pppClassList = pppClassList;
	}

	public List getPppList() {
		return pppList;
	}

	public void setPppList(List pppList) {
		this.pppList = pppList;
	}

	IPerfcrittypeBO pctBo;
	IPerfschematypeBO pstBo;
	IPerfplanperiodBO pppBo;
	private List crittypeList;
	private List schematypeList;
	private Map pppClassList;
	private List pppList;
	protected static final String SUCC = "SUCC";
	protected static final String FAIL = "FAIL";
}
